#include <stdio.h>
#include <string.h>


//char *p = "abcd1111abcd222abcd3333" 请你找出字符串abcd出现的次数



/*
#include <string.h>

char *strstr(const char *haystack, const char *needle);
DESCRIPTION
    The strstr() function locates the first occurrence of the null-terminated
    string needle in the null-terminated string haystack.

RETURN VALUES
     If needle is an empty string, haystack is returned; if needle occurs
     nowhere in haystack, NULL is returned; otherwise a pointer to the first
     character of the first occurrence of needle is returned.
*/


int find_how_many_occurs(char *source, char *token)
{
    int count=0;

    char *tmp_p = source;
    
    int len = strlen(token);

    do
    {
        tmp_p = strstr(tmp_p,token);
        if(tmp_p == NULL)//if needle occurs nowhere in haystack, NULL is returned
        {
            break;
        }
        tmp_p += len;
        count++;
    }while(tmp_p != '\0');

    return count;
}

int main(void)
{
    char *source = "abcd1111abcd222abcd3333";
    char *token = "abcd";
   
    int ret = find_how_many_occurs(source, token);
    
    

    printf("%d\n",ret);

}